<?php
class BaseClass extends Controller {

	public $loggedInUser = null;
	public $selectedNavMenu = 1;
	public $randomCategories = null;
	public $dateArr = null;
    function init() {
        parent::init();
		error_reporting(E_ALL);
        $app = Yii::app();
       
        //Get login info
        if(isset(Yii::app()->user->userId)){
        	//Session related checks - session timeout
        	$current_time = time();
        	if(Yii::app()->request->isAjaxRequest==false && isset(Yii::app()->session['login_time']) && ($current_time - Yii::app()->session['login_time']) > Yii::app()->session['sess_timeout'])
        	{
        		Yii::app()->session['login_time'] = null;
        		Yii::app()->session['timed_out'] = 1;
        	}
        	
        	//$this->loggedInUser = $this->getUserInfoByEmailId(Yii::app()->user->Id);
        } else {
        	$this->loggedInUser = null;
        	$this->redirect('/admin');
        }
    }
    /*
     * method for getting the list of admins
     * 
     */
    function getAdmins() {
        $records = Users::model()->findall(array('condition' => "`role` = 1"));
        $adminArr = array();
        foreach ($records as $record) {
            $adminArr[] = $record->username;
        }
        return $adminArr;
    }
    
    function getSubAdmins() {
    	$records = Users::model()->findall(array('condition' => "`role` = 2"));
    	$adminArr = array();
    	foreach ($records as $record) {
    		$adminArr[] = $record->username;
    	}
    	return $adminArr;
    }
    
    public function generateNewNameOfImage($image_name) {
    	$extension = substr($image_name, strrpos($image_name, '.')+1);
    	$name = md5(date("Y-m-d") * mt_rand());
    	return $name.".".strtolower($extension);
    }
    
    public function getExtension($name){
    	return substr($name, strrpos($name, '.')+1);
    }
    
    public function pr($data){
    	echo "<pre>";
    		print_r($data);
    	echo "</pre>";
    	exit;
    }
}
